package com.atung.provider;

import java.util.Objects;

import org.apache.ibatis.jdbc.SQL;

import com.atung.model.BusCarAllocation;

public class BusCarAllocationProvider {

	public String saveBusCarAllocationProvider(BusCarAllocation BusCarAllocation){
		return new SQL(){
			{
				INSERT_INTO("bus_car_allocation");
				VALUES("id", "#{id}");
				VALUES("publish_id", "#{publishId}");
				VALUES("current_nember", "#{currentNember}");
				VALUES("car_id", "#{carId}");
				if(Objects.nonNull(BusCarAllocation.getIsDelect())){
					VALUES("is_delect", "#{isDelect}");
				}
				if(Objects.nonNull(BusCarAllocation.getAllocationState())){
					VALUES("allocation_state", "#{allocationState}");
				}
				VALUES("creation_time", "#{creationTime}");
				VALUES("modification_time", "#{modificationTime}");
			}
		}.toString();
	}
	
	public String updateBusCarAllocationProvider(BusCarAllocation BusCarAllocation){
		return new SQL(){
			{
				UPDATE("bus_car_allocation");
			
				if(Objects.nonNull(BusCarAllocation.getCurrentNember())){
					SET("current_nember=#{currentNember}");
				}
				
				if(Objects.nonNull(BusCarAllocation.getCarId())){
					SET("car_id=#{carId}");
				}
				
				if(Objects.nonNull(BusCarAllocation.getIsDelect())){
					SET("is_delect=#{isDelect}");
				}
				SET("modification_time=#{modificationTime}");
				WHERE("id=#{id}");
			}
		}.toString();
	}
}
